<%@page import="com.hhit.collaborative_learning.entity.DataPage"%>
<%@page import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@page import="com.hhit.collaborative_learning.utils.Utils"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String type=request.getParameter("type");
	type=type==null?"in":type;
	String currentPage=request.getParameter("currentPage");
	String userId=request.getParameter("userId");
	userId=userId==null?Utils.getCookieValue("userId", request):userId;
	PublicDaoImplMySql dao=new PublicDaoImplMySql();
	DataPage dataPage=dao.getMyData(Integer.parseInt(userId), type, currentPage);
	request.setAttribute("page", dataPage);
	request.setAttribute("userId", userId);
	request.setAttribute("type", type);
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<%=basePath%>css/download.css" rel="stylesheet"
	type="text/css" />
<!-- test toolbar nav-->
<link rel="stylesheet" href="<%=basePath%>css/index.css">
<script src="<%=basePath%>js/jquery-1.11.1.min.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>css/News-nav.css">
<!-- toolbar nav -->
<script language='JavaScript' type='text/javascript'
	src='<%=basePath%>js/jquery.form.js'></script>
<script language='JavaScript' type='text/javascript'
	src='<%=basePath%>js/jquery.cookie.js'></script>
</head>
<body>
	<!-- toolbar nav -->
	<div class="news-nav">
		<div class="container clearfix">
			<div class="nav-bar">
				
				<a <c:if test="${userId ne cookie.userId.value }">class="current"</c:if> href="<%=basePath%>download/download.jsp" target="_top">首页</a> 
				<a <c:if test="${userId eq cookie.userId.value }">class="current"</c:if> href="<%=basePath %>download/mydata.jsp">我的资源</a>
				<a href="<%=basePath%>download/search.jsp?type=3" target="_blank">搜索</a>
			</div>
		</div>
	</div>
	<!-- //toolbar nav -->
	<div id="wrap">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>css/bootstrap_download.min.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>css/common_download2.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>css/panels.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>css/style_download.css">
		<link href="<%=basePath%>css/my-upload.css" rel="stylesheet">
		<div class="bd clearfix">
			<div class="container">
				<div class="bread-crumbs mb-bg">
					<c:choose>
						<c:when test="${userId eq cookie.userId.value}">
							<span>我的资源</span>
						</c:when>
						<c:otherwise>
							<span>首页</span><em class="to-icon">&gt;</em><span><%=dao.getUserNickName(Integer.parseInt(userId)) %>的资源</span>
						</c:otherwise>
					</c:choose>
				</div>
			</div>
			<div class="container">
				<ul class="nav nav-tabs">
					<li <%if(type.equals("in")){ %>class="active"<%} %>><a href="<%=basePath%>download/mydata.jsp?userId=<%=userId%>">上传资源</a></li>
					<li <%if(type.equals("out")){ %>class="active"<%} %>><a href="<%=basePath%>download/mydata.jsp?type=out&userId=<%=userId%>">下载资源</a></li>
				</ul>
				<div class="list-container mb-bg">
					<c:forEach items="${page.list}" var="data">
						<dl>
							<dt>
								<c:if test="${type eq 'in' && userId eq cookie.userId.value}">
									<div class="btns">
										<a href="javascript:void(0)" onclick="del_my_src('${data.dataId}');"
											class="btn btn-remove">删除</a>
									</div>
								</c:if>
								<!--  <div class="btns"><span class="removed">资源已删除</span><span class="commented">已评价</span><a href="#" class="btn-comment">立即评价，通过可返分</a></div>
	              -->
								<h3>
									<a href="<%=basePath%>download/downloadpage.jsp?dataId=${data.dataId}" target="_blank">${data.dataName}</a><span
										class="points">${data.dataPoint}</span>
								</h3>
							</dt>
							<dd class="meta">
								上传者：<a class="user_name" href="/user/u013534446">
								${data.dataUserName}
								</a>&nbsp;&nbsp;&nbsp;&nbsp;|
								上传时间：${data.dataTime}&nbsp;&nbsp;&nbsp;&nbsp;| 下载${data.dataPoint}次
							</dd>
							<dd class="intro">${data.dataDesc }</dd>
							<dd class="tag">
								<c:forEach items="${data.dataTag}" var="tag">
									<a href="javascript:void(0);">${tag}</a>
								</c:forEach>
							</dd>
						</dl>
					</c:forEach>
					<c:if test="${page.count eq 0}">
						<dl>
							<dt class="empty">
								<%if(type.equals("in")){ %>
								提示：你还没有上传资源~<a href="/upload"> 现在去上传</a>
								<%}else{ %>
								提示：你还没有下载资源~
								<%} %>
							</dt>
						</dl>
					</c:if>
					<div class="page_nav">
						<c:if test="${page.totalPage gt 1 }">
							<span>共${requestScope.page.totalPage}页</span>
								<c:if test="${requestScope.page.currentPage>1}">
									<a href="mydata.jsp?type=<%=type%>&currentPage=1&userId=<%=userId%>">首页</a>
									<a
										href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.currentPage-1}&userId=<%=userId%>">上一页</a>
								</c:if>
								<c:if test="${requestScope.page.pageDiffer>0}">
									<a
										href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5-4}&userId=<%=userId%>">...</a>
								</c:if>

								<c:if
									test="${requestScope.page.pageDiffer*5+1<=requestScope.page.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.page.currentPage==requestScope.page.pageDiffer*5+1 }">
											<strong>${requestScope.page.pageDiffer*5+1}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+1}&userId=<%=userId%>">${requestScope.page.pageDiffer*5+1}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.page.pageDiffer*5+2<=requestScope.page.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.page.currentPage==requestScope.page.pageDiffer*5+2 }">
											<strong>${requestScope.page.pageDiffer*5+2}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+2}&userId=<%=userId%>">${requestScope.page.pageDiffer*5+2}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.page.pageDiffer*5+3<=requestScope.page.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.page.currentPage==requestScope.page.pageDiffer*5+3 }">
											<strong>${requestScope.page.pageDiffer*5+3}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+3}&userId=<%=userId%>">${requestScope.page.pageDiffer*5+3}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.page.pageDiffer*5+4<=requestScope.page.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.page.currentPage==requestScope.page.pageDiffer*5+4 }">
											<strong>${requestScope.page.pageDiffer*5+4}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+4}&userId=<%=userId%>">${requestScope.page.pageDiffer*5+4}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.page.pageDiffer*5+5<=requestScope.page.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.page.currentPage==requestScope.page.pageDiffer*5+5 }">
											<strong>${requestScope.page.pageDiffer*5+5}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+5}&userId=<%=userId%>">${requestScope.page.pageDiffer*5+5}</a>
										</c:otherwise>
									</c:choose>
								</c:if>
								<c:if
									test="${requestScope.page.totalPage>5 && requestScope.page.pageDiffer<requestScope.page.totalPage/5-1}">
									<a
										href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.pageDiffer*5+6}&userId=<%=userId%>">...</a>
								</c:if>
								<c:if
									test="${requestScope.page.currentPage<requestScope.page.totalPage}">
									<a
										href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.currentPage+1}&userId=<%=userId%>">下一页</a>
									<a
										href="mydata.jsp?type=<%=type%>&currentPage=${requestScope.page.totalPage}&userId=<%=userId%>">尾页</a>
								</c:if>
						</c:if>
					</div>
				</div>
			</div>
<!-- 			<div class="aside"> -->
<!-- 				<div id="my-info"> -->
<!-- 					<div class="avatar"> -->
<!-- 						<img src="<%=basePath%>userIcons/${cookie.userIcon.value}"> -->
<!-- 					</div> -->
<!-- 					<div class="avatar"> -->
<!-- 						<a href="http://my.csdn.net/u013534446" target="_blank">u013534446</a> -->
<!-- 					</div> -->
<!-- 					<div class="points"> -->
<!-- 						<em>积 分：8</em><br> 上传资源：<span class="red">0</span><br> -->
<!-- 						下载资源：<span class="red">29</span><br>  -->
<!-- 						<em>总 排 名</em>：第<span -->
<!-- 							class="red">19377439</span>名<br> -->
<!-- 						<br> 上传权限：<span class="red">60MB</span> -->
<!-- 					</div> -->

					<!-- 					<div class="tip">提示：再增加92下载积分，即可升级到下一级 。</div> -->
<!-- 				</div> -->
<!-- 				<a href="/upload" class="btn btn-lg btn-upload">上传我的资源</a> -->
<!-- 				<a href="/album/rule" class="btn btn-lg btn-create">创建专辑</a> -->
<!-- 				<div id="my-tags-side" class="panel panel-default"> -->
<!-- 					<div class="panel-heading"> -->
<!-- 						<h3 class="panel-title">我的Tag</h3> -->
<!-- 					</div> -->
<!-- 					<div class="panel-body"> -->
<!-- 						<ul class="list-inline"> -->

<!-- 						</ul> -->
<!-- 					</div> -->
<!-- 				</div> -->

<!-- 			</div> -->
		</div>
		<script type="text/javascript">
// 			function cancel_fav(sourcename, id) {
// 				if (confirm("您确定要取消对" + sourcename + "的收藏吗？")) {
// 					$.get("/index.php/favorite/cancel_fav/" + id,
// 							function(data) {
// 								data = eval('(' + data + ')');
// 								alert(data.msg);
// 								window.location.reload();
// 							});
// 				}
// 			}

			function del_my_src(id) {
				if (confirm("一旦删除将不可恢复，您确定要删除吗？")) {
					$.get("<%=basePath%>DeleteDataServlet?dataId=" + id,
							function(ret,status) {
								if(ret=='true'){
									alert('删除成功！');
									window.location.reload();
								}else{
									alert('删除失败！');
								}
							});
				}

			}
		</script>
		<!-- 计数  -->
	</div>

	<link href="<%=basePath%>css/ask_float_block.css" rel="stylesheet"
		type="text/css" />
</body>
</html>
